package com.kaibes.platform.menu;

import java.util.List;

import org.springframework.stereotype.Service;

import com.kaibes.core.base.option.NullOptions;
import com.kaibes.orm.core.plus.InsertBuilderPlus;
import com.kaibes.orm.curd.QueryBuilder;
import com.kaibes.web.api.ResponseServiceImpl;

@Service
public class MenuService extends ResponseServiceImpl<Menu> {

    public Menu getByHref(String href) {
        return get(QueryBuilder.newBuilder().eq("href", href).build());
    }

    @Override
    public <T> List<T> save(Object data) {
        return getMapper().insert(InsertBuilderPlus.newBuilder().addData(data).null2Zero("sort").zero2Null("parentId").null2True("enable").build());
    }
    
    public String getNameById(Short id) {
        return NullOptions.returnString(getById(id, "name"), menu->menu.getName());
    }
    
    public List<Menu> listByType(String type) {
        return list(QueryBuilder.newBuilder().eq("type", type).build());
    }

}
